<?php
/**
 * Created by PhpStorm.
 * User: qingyun
 * Date: 2019/5/16
 * Time: 1:37 PM
 */
namespace app\index\controller;

use think\Controller;

class Company extends Controller
{

    public function add_leader(){

        if ($this->request->isPost()){

            $data = $this->request->only(['name','sex','company_id']);
            //todo 验证数据
//            $rule= [];
//            $msg=[];
//            $this->validate($data,$rule,$msg);
            //入库

            if (\think\Db::table('leader')->data($data)->insert()){

                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }

        }

    }


    public function add_job(){

        if ($this->request->isPost()){

            $data = $this->request->only(['name','company_id']);

            //todo 数据验证
            $rule= [];
//            $msg=[];
//            $this->validate($data,$rule,$msg);
            //入库
            if (\think\Db::table('job')->data($data)->insert()){

                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }
        }

    }


    public function yelp(){

        $user = userInfo();
        if (empty($user)){
            $this->error('您需要先登录后才能操作');
        }

        if ($this->request->isPost()){

            $data = $this->request->only(['score','salary','job_id']);
            //todo 数据验证
//            $rule = [];
//            $msg = [];
//            $this->validate($data,$rule,$msg);
            $data['uid'] = $user->id;
            $data['create_time'] = time();

            //一个月之内只能为一个工作点评一次
            $last = \think\Db::table('job_yelp')->order('create_time DESC')->where('job_id',$data['job_id'])->where('uid',$user->id)->value('create_time');
            if ($last >time()-2592000){
                $this->error('一个月之内只能点评一次');
            }



            //入库
            if (\think\Db::table('job_yelp')->data($data)->insert()){

                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }


        }

        if ($this->request->isGet()){
            $id = $this->request->param('id');

            $info = \think\Db::table('job')->where('id',$id)->find();
            $this->assign('info',$info);


            //统计薪资水平
            $m = \think\Db::table('job_yelp');





            return $this->fetch();


        }






    }







}


















